#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <sstream>
#include <stdlib.h>
#include <cstring>
#include <algorithm>
using namespace std;

//按道理来说是用二叉树遍历，比如先序遍历来做。但是这里没有二叉树
//其实好像也是同样的道理而已。直接写吧
struct Node
{
  int weight, left, right;
};
map<int, Node> m; // 用map的话，多出了logn的查找时间，会超时
Node nodes[100001];
int max_xor_res = -1e7;

void preOrder(int cur_id, int xor_res)
{
  //记得vector中索引要+1
  Node cur_node = nodes[cur_id];
  int cur_xor_res = xor_res ^ cur_node.weight;
  if (cur_xor_res > max_xor_res)
    max_xor_res = cur_xor_res;
  if (cur_node.left != -1)
  {
    preOrder(cur_node.left, cur_xor_res);
  }

  if (cur_node.right != -1)
  {
    preOrder(cur_node.right, cur_xor_res);
  }
}

int main()
{
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    int id;
    cin >> id;
    Node tem;
    cin >> tem.weight >> tem.left >> tem.right;
    m[id] = tem;
    nodes[id] = tem;
  }
  for (int i = 1; i <= n; i++)
    preOrder(i, 0);
  for (int i = n - 1; i >= 0; i--)
    preOrder(i, 0);
  cout << max_xor_res << endl;
}